//
//  StatusTableViewTopView.swift
//  DSWeibo
//
//  Created by J on 16/4/30.
//  Copyright © 2016年 J. All rights reserved.
//

import UIKit

class StatusTableViewTopView: UIView {
    override init(frame: CGRect) {
        super.init(frame: frame)
        //        self.backgroundColor = UIColor.orangeColor()
        //初始化UI
        setupUI()
    }

    
    var  status : Statuses?{
        
        didSet{
            
            nameLabel.text = status?.user?.name
            timeLabel.text = status?.created_at
            //设置用户头像
            if let iconUrl = status?.user?.profile_image_url_URL{
                iconView.sd_setImageWithURL(iconUrl)
            }
            //设置认证图标
            vertifiedView.image = status?.user?.vetifiedImage
            
            //设置会员图标
            vipView.image = status?.user?.mbrankImage
            
            ///  设置来源
            sourceLabel.text = status?.source
            
            
        }
        
    }

    
    private func setupUI() {
        //1.添加子控件
        addSubview(iconView)
        addSubview(vertifiedView)
        addSubview(nameLabel)
        addSubview(vipView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        
        
        
        
        iconView.snp_makeConstraints { (make) in
            make.left.equalTo(self).offset(30)
            make.top.equalTo(self).offset(30)
            make.size.equalTo(CGSizeMake(50, 50))
        }
        //2.布局子控件
        vertifiedView.snp_makeConstraints { (make) in
            let size = vertifiedView.image?.size
            make.size.equalTo((vertifiedView.image?.size)!)
            make.top.equalTo(iconView.snp_bottom).offset(-size!.height*0.5)
            make.left.equalTo(iconView.snp_bottom).offset(-size!.width*0.5)
            
        }
        
        
        
        vipView.snp_makeConstraints { (make) in
            make.left.equalTo(nameLabel.snp_right).offset(5)
            make.centerY.equalTo(nameLabel)
            make.size.equalTo(vipView.image!.size)
        }
        
        nameLabel.snp_makeConstraints { (make) in
            make.left.equalTo(iconView.snp_right).offset(20)
            make.top.equalTo(iconView)
            make.height.equalTo(30)
        }
        
        timeLabel.snp_makeConstraints { (make) in
            make.left.equalTo(nameLabel)
            make.top.equalTo(nameLabel.snp_bottom)
        }
        
        
        
        sourceLabel.snp_makeConstraints { (make) in
            make.left.equalTo(timeLabel.snp_right).offset(5)
            make.top.equalTo(timeLabel)
        }


    }
    
    
    //MARK: - 懒加载
    ///  头像
    private lazy var iconView : UIImageView = {
        
        let iv = UIImageView(image: UIImage(named: "avatar_default_big"))
        return iv
    }()
    ///认证图标
    private lazy var vertifiedView : UIImageView = UIImageView(image: UIImage(named: "avatar_enterprise_vip"))
    ///昵称
    private lazy var nameLabel : UILabel = UILabel.createLabel(UIColor.darkGrayColor(), font: 14)
    
    ///会员图标
    private lazy var vipView : UIImageView = {
        
        let iv = UIImageView(image: UIImage(named: "common_icon_membership_level2"))
        return iv
    }()
    ///时间
    private lazy var timeLabel : UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFontOfSize(14)
        return label
    }()
    
    ///  来源
    private lazy var sourceLabel : UILabel = UILabel.createLabel(UIColor.blueColor(), font:14 )
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    
}
